﻿@{
    ViewBag.Title = "LiveIndex";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}@using LeSoft.Application.Code;
<script>
    var _organizeid = "@OperatorProvider.Provider.Current().CompanyId";
    var pstructName = "";
    var _pstructId = "", _state = 0;
    $(function () {
        InitialPage();
        GetGrid();
        GetTree1();
        GetTree2();
    });
    //初始化页面
    function InitialPage() {
        //layout布局
        $('#layout').layout({
            applyDemoStyles: true,
            onresize: function () {
                $(window).resize()
            }
        });
        //resize重设(表格、树形)宽高
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $('#gridTable').setGridWidth(($('.gridPanel').width()));
                $("#gridTable").setGridHeight($(window).height() - 141.5);
                $("#itemTree").setTreeHeight($(window).height() - 55.5);
            }, 200);
            e.stopPropagation();
        });
        //组织机构
        $("#OrganizeTree").ComboBoxTree({
            url: "../../BaseManage/Organize/GetTreeJsonById",
            description: "==请选择组织机构==",
            height: "250px",
            click: function (item) {
                _organizeid = item.id;
                GetTree1();
                $('#btn_Search').trigger("click");
            }
        });
        $("#OrganizeTree").ComboBoxTreeSetValue(_organizeid);
        //初始化时间
        $("#StartTime").val("@DateTime.Now.AddDays(-DateTime.Now.Day+1).ToString("yyyy-MM-dd")");
        $("#EndTime").val("@DateTime.Now.AddMonths(1).AddDays(- DateTime.Now.Day).ToString("yyyy-MM-dd")");
        $("#time_horizon").ComboBox({
            data: [{ "key": 2, "value": "上周" }, { "key": 1, "value": "本周" }, { "key": 4, "value": "上月" }, { "key": 3, "value": "本月" }, { "key": 5, "value": "本年" }],
            id: "key",
            text: "value",
            click: function (item) {

                var value = item.attr('data-value');
                switch (value) {
                    case "1"://本周
                        $("#StartTime").val("@DateTime.Now.AddDays(1 - DateTime.Now.DayOfWeek.GetHashCode()).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddDays(7 - DateTime.Now.DayOfWeek.GetHashCode()).ToString("yyyy-MM-dd")");
                        break;
                    case "2"://上周
                        $("#StartTime").val("@DateTime.Now.AddDays(1 - DateTime.Now.DayOfWeek.GetHashCode()-7).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddDays(7 - DateTime.Now.DayOfWeek.GetHashCode()-7).ToString("yyyy-MM-dd")");
                        break;
                    case "3"://本月
                        $("#StartTime").val("@DateTime.Now.AddDays(-DateTime.Now.Day+1).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddMonths(1).AddDays(- DateTime.Now.Day).ToString("yyyy-MM-dd")");
                        break;
                    case "4"://上月
                        $("#StartTime").val("@DateTime.Now.AddDays(-DateTime.Now.Day + 1).AddMonths(-1).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddDays(-DateTime.Now.Day).ToString("yyyy-MM-dd")");
                        break;
                    case "5"://本年
                        $("#StartTime").val("@DateTime.Now.AddDays(-DateTime.Now.DayOfYear + 1).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddMonths(12 - DateTime.Now.Month + 1).AddDays(-DateTime.Now.Day).ToString("yyyy-MM-dd")");
                        break;
                    default:
                        break;
                }
                $("#SelectedStartTime").html($("#StartTime").val());
                $("#SelectedEndTime").html($("#EndTime").val());
                $('#btn_Search').trigger("click");
            }
        });
        $("#time_horizon").ComboBoxSetValue(3);
    }

    function GetTree1() {
        var item = {
            height: 313,
            url: "../../ResourceManage/RS_PStructUser/GetStateCountTreeList",
            onnodeclick: function (item) { 
                switch (item.id) {
                    case "All":
                        _state = 0;
                        break;
                    case "S1": case "S11": case "S2": case "S13":
                        _state = 1;
                        break;
                    case "S2": case "S21":
                        _state = 2;
                        break;
                    case "S3":
                        _state = 3;
                        break;
                    case "S4":
                        _state = 4;
                        break;
                    case "S5":
                        _state = 5;
                        break; 
                    default:

                } 
                $('#btn_Search').trigger("click");
            }
        };
        //初始化
        $("#itemTree1").treeview(item);
    }
    function GetTree2() {
        var item = {
            height: $(window).height() -400,
            url: "../../ResourceManage/RS_PStructs/GetTreeJson?type=5&IsSubstep=true&organizeid=" + _organizeid,
            onnodeclick: function (item) {
                if (_pstructId != item.id) {
                    _pstructId = item.id; 
                    $('#btn_Search').trigger("click");
                }
            }
        };
        //初始化
        $("#itemTree2").treeview(item);
        if (!!_pstructId) {
            var re = new RegExp("-", "g");
            $("#itemTree2_" + _pstructId.replace(re, '_')).addClass("bbit-tree-selected");
        }
    }


    function GetGrid() {
        var selectedRowIndex = 0;
        var $gridTable = $('#gridTable');
        var queryJson = {
            OrganizeId: _organizeid,
            State: _state,
            StartTime: $("#StartTime").val(),
            EndTime: $("#EndTime").val(),
            Code: $("#Code").val(),
            PStructId: _pstructId
        }; 
        $gridTable.jqGrid({
            url: "../../ResourceManage/RS_PStructUser/GetLiveInBillPageList",
            postData: { queryJson: JSON.stringify(queryJson) },
            datatype: "json",
            height: $(window).height() - 141.5,
            autowidth: true,
            colModel: [
               { label: "主键", name: "id", index: "id", hidden: true },
               { label: "单据编号", name: "code", index: "code", width: 200, align: "center", sortable: true },
               { label: "单据日期", name: "createdate", index: "createdate", width: 120, align: "center", sortable: true },
               {
                   label: "状态", name: "state", index: "state", width: 80, align: "center", sortable: true,
                   formatter: function (cellvalue) {
                       var State = "";
                       switch (cellvalue) {
                           case "1": case 1: State = "待提交"; break;
                           case "2": case 2: State = "审核中"; break;
                           case "3": case 3: State = "待确定"; break;
                           case "4": case 4: State = "已入住"; break;
                           case "5": case 5: State = "退住中"; break;
                           case "6": case 6: State = "已退住"; break;
                           default: State = cellvalue; break; 
                       }
                       return State;
                   }
               },
               { label: "房产描述", name: "pstructmemo", index: "pstructmemo", width: 150, align: "center", sortable: true },
               { label: "入住日期", name: "begindate", index: "begindate", width: 120, align: "center", sortable: true },
               { label: "租户名称", name: "name", index: "name", width: 150, align: "center", sortable: true },
               { label: "租户编号", name: "ccode", index: "ccode", width: 150, align: "center", sortable: true },
               { label: "联系人", name: "linkman", index: "linknman", width: 150, align: "center", sortable: true },
               { label: "联系电话", name: "linkphonenum", index: "linkphonenum", width: 150, align: "center", sortable: true },
               { label: "退住时间", name: "enddate", index: "enddate", width: 120, align: "center", sortable: true },
               { label: "附加说明", name: "description", index: "description", width: 150, align: "center", sortable: true }

            ],
            rowNum: 30,
            rowList: [30, 50, 100],
            pager: "#gridPager",
            sortable: true,
            sortname: 'Code',
            sortorder: 'desc',
            rownumbers: true,
            shrinkToFit: false,
            gridview: true,
            onSelectRow: function () {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            }
        })
        //查询事件
        $("#btn_Search").click(function () {
            var queryJson = {
                OrganizeId: _organizeid,
                State: _state,
                StartTime: $("#StartTime").val(),
                EndTime: $("#EndTime").val(),
                Code: $("#Code").val(),
                PStructId: _pstructId
            };
            $("#gridTable").jqGrid('setGridParam', {
                url: "../../ResourceManage/RS_PStructUser/GetLiveInBillPageList",
                postData: { queryJson: JSON.stringify(queryJson) },
            }).trigger('reloadGrid');
        });
        $("#btn_Reset").click(function () {
            $("#Code").val("");
            $("#EndTime").val("");
            $("#StartTime").val("");
        })
    }
    //查看
    function btn_Open() {
        var keyValue = $("#gridTable").jqGridRowValue("id");
         if (checkedRow(keyValue)) {
            dialogOpen({
                id: "Form",
                title: '入住单详情',
                url: '/ResourceManage/RS_PStructUser/LiveBillForm?keyValue=' + keyValue,
                width: "1100px",
                height: "800px",
                callBack: function (iframeId) {
                    top.frames[iframeId].AcceptClick();
                },
                btn: null
            });
         }
       
    };
    function btn_Add()
    {
        dialogOpen({
            id: "Form",
            title: '新增入住单',
            url: '/ResourceManage/RS_PStructUser/AddForm',
            width: "1000px",
            height: "700px",
            callBack: function (iframeId) {
                top.frames[iframeId].AcceptClick();
            }, 
        });
    }

</script>
<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div class="ui-layout-west">
        <div class="west-Panel">
            <div class="panel-Title" style="padding:0px; text-align:center;">单据状态</div>
            <div id="itemTree1" style=" height: 320px;"></div>
            <div class="panel-Title" style="padding:0px;"><div id="OrganizeTree" type="selectTree" class="ui-select"></div></div>
            <div id="itemTree2" style=" height: 320px;"></div>
        </div>
    </div>
    <div class="ui-layout-center">
        <div class="center-Panel">
            <div class="titlePanel">
                <div class="title-search">
                    <table>
                        <tr>
                            <td>查询条件</td>
                            <td style="padding-left: 10px;">
                                <div class="ui-filter" style="width: 200px;  ">
                                    <div class="ui-filter-text">
                                        <strong id="SelectedStartTime">@DateTime.Now.AddDays(-DateTime.Now.Day + 1).ToString("yyyy-MM-dd")</strong> 至 <strong id="SelectedEndTime">@DateTime.Now.AddMonths(1).AddDays(-DateTime.Now.Day).ToString("yyyy-MM-dd")</strong>
                                    </div>
                                    <div class="ui-filter-list" style="width: 350px;">
                                        <table class="form" id="filter-form">
                                            <tr>
                                                <th class="formTitle">发布时间：</th>
                                                <td class="formValue">
                                                    <div style="float: left; width: 45%;">
                                                        <input id="StartTime" readonly type="text" value="" class="form-control input-wdatepicker" onfocus="WdatePicker()">
                                                    </div>
                                                    <div style="float: left; width: 10%; text-align: center;">至</div>
                                                    <div style="float: left; width: 45%;">
                                                        <input id="EndTime" readonly type="text" value="2017-07-31" class="form-control input-wdatepicker" onfocus="WdatePicker()">
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="formTitle">单据编号：</td>
                                                <td class="formValue">
                                                    <input id="Code" type="text" class="form-control">
                                                </td>
                                            </tr>

                                        </table>
                                        <div class="ui-filter-list-bottom">
                                            <a id="btn_Reset" class="btn btn-default">&nbsp;重&nbsp;&nbsp;置</a>
                                            <a id="btn_Search" class="btn btn-primary">&nbsp;查&nbsp;&nbsp;询</a>
                                        </div>
                                    </div>
                                </div>
                            </td>
                            <td style="padding-left: 10px;">
                                <div id="time_horizon" type="selectTree" class="ui-select" style="width: 60px;"></div>
                            </td>
                        </tr>

                    </table>
                </div>
                <div class="toolbar">
                    <div class="btn-group">
                        <a id="lr-replace" class="btn btn-default" onclick="reload();"><i class="fa fa-refresh"></i>&nbsp;刷新</a>
                        <a id="lr-add" class="btn btn-default" onclick="btn_Add()"><i class="fa fa-plus"></i>&nbsp;新增</a>
                        <a id="lr-detail" class="btn btn-default" onclick="btn_Open()"><i class="fa fa-eye"></i>&nbsp;查看</a>
                    </div>
                    @*<script>$('.toolbar').authorizeButton()</script>*@
                </div>
            </div>
            <div class="gridPanel">
                <table id="gridTable"></table>
                <div id="gridPager"></div>
            </div>
        </div>
    </div>
</div>

